/**
 * 授权登陆
 */
class LoginScene extends Scene {


	public constructor() {
		super();
		this.skinName = LoginSceneSkin;
		platform.setButton((code, e) => {
			if (e.userInfo) {
				platform.headButton();
				this.code = code;
				this.encryptedData = e.encryptedData;
				this.iv = e.iv;
				this.login();
			} else {
				SceneManager.ins.alert("授权失败，请重新授权");
			}
		});
	}


	private code;
	private inpName;
	private encryptedData;
	private iv;


	/**
	 * 登陆
	 */
	private login() {
		Net.ins.send(['user', 'register'], {
			"code": this.code,
			"encryptedData": encodeURIComponent(this.encryptedData),
			"iv": encodeURIComponent(this.iv),
			"pid": platform.up_id,
			"stype": platform.stype
		}, (e) => {

			// 修改这里时别忘了改  main 里 ^^
			PlayerSelfData.gold = e.gold;
			platform.token = e.openid;
			PlayerSelfData.userinfo = e;
			platform.userinfo = e;

			platform.initShare();

			// 化肥信息初始化
			PlayerSelfData.manure["expire"] = 0;
			PlayerSelfData.manure["number"] = 0;
			PlayerSelfData.manure["today_use"] = 4;
			// 修改这里时别忘了改  main 里 $$
			LoadScene.ins.load("main", new MainScene());
		})
	}

}